package controller.validator;

import java.util.ArrayList;

import exception.InputValidationErrors;

/**
 * Implements validation for adding, updating or deleting completed course.
 * 
 * @author huangjm.2012, jaslin.wee.2012
 * 
 */
public class CompletedCourseValidator extends Validator {

	private String userId;

	private String completedCourseCode;

	public String getUserId() {
		return userId;
	}

	public String getCompletedCourseCode() {
		return completedCourseCode;
	}

	public CompletedCourseValidator(String courseCode, String userId) {
		this.userId = userId;
		this.completedCourseCode = courseCode;
	}

	@Override
	public void performValidationBeforeAdding() throws InputValidationErrors {

		/*
		 * Array list to store logic error messages
		 */
		ArrayList<String> logicErrors = new ArrayList<String>();

		/*
		 * Validation for invalid userid
		 */
		try {
			checkForStudent(userId);
		} catch (Exception e) {
			logicErrors.add(Validator.INVALID_USERID);
		}

		/*
		 * Validation for invalid code
		 */
		try {
			checkForCourse(completedCourseCode);
		} catch (Exception e) {
			logicErrors.add(Validator.INVALID_CODE);
		}

		/*
		 * Throw exception
		 */
		if (!logicErrors.isEmpty()) {
			throw new InputValidationErrors(logicErrors);
		} else {

			/*
			 * Validation for invalid course completed
			 */
			try {
				checkForPreRequisitesCompletion(userId, completedCourseCode);
			} catch (Exception e) {
				logicErrors.add(Validator.INVALID_COURSE_COMPLETED);
			}

			if (!logicErrors.isEmpty()) {
				throw new InputValidationErrors(logicErrors);
			}

		}

	}

	@Override
	public void performValidationBeforeUpdating() throws InputValidationErrors {
		// TODO Auto-generated method stub

	}

	@Override
	public void performValidationBeforeDeleting() throws InputValidationErrors {
		// TODO Auto-generated method stub

	}

}
